import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

public class TopologyReader {

	public void readFile(String filePath) {

		String delims = "[ :]";
		try {
			Scanner s = new Scanner(new FileInputStream(new File(filePath)));
			boolean firstPartOfTheFile = true;
			while (s.hasNextLine()) {
				String line = s.nextLine();
				if (line.length() < 5) {
					firstPartOfTheFile = false;
					line = s.nextLine();
				}
				String[] tokens = line.split(delims);
				if (firstPartOfTheFile) {
					int nodeStart = Integer.parseInt(tokens[1]);					
					int nodeStop = Integer.parseInt(tokens[3]);					
					int latency = Integer.parseInt(tokens[5]);
					int bw_mult = Integer.parseInt(tokens[7]);
					int link_weight = Integer.parseInt(tokens[9]);
					
					Node n1=Node.create(nodeStart);
					Node n2=Node.create(nodeStop);
					Bus conn=Bus.create(n1, n2, latency, bw_mult, link_weight);
					
					n1.addVecin(n2, conn);
					//n2.addVecin(n1); //nu e nevoie caci e dat in tabela pe ambele parti
					//System.out.println(nodeStart + " " + nodeStop + " "
					//		+ latency + " " + bw_mult + " " + link_weight);
				} else {
					int rtable_cur = Integer.parseInt(tokens[1]);
					int rtable_dst = Integer.parseInt(tokens[3]);
					int rtable_nxt = Integer.parseInt(tokens[5]);
					int rtable_vc = Integer.parseInt(tokens[7]);
					
					Node cur=DataStore.getInstance().getNode(rtable_cur); //the node in which's table we add
					Node dst= Node.create(rtable_dst);					
					Node nxt=Node.create(rtable_nxt);
					cur.routeAdd(dst, nxt);
					cur.setVcs(dst, rtable_vc);
					//cum folosim si unde VCs ?
					
				}
			}
			s.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
